// pages/proposalfordissolution/proposalfordissolution.js
import {
    getcheckdismisscompanystatusapi,
    dismisscompanyapi
} from '../api/personalMsg'
import user from '../../utils/user'
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        isselect: '',
        resonlist: [],
        password: '',
        id: '',
        isUptwo: false,
        hasreasonmsg: {},
        isopeneye: false,
        isUp: false,
        areavalue: '',
        num: 0,
        selectlist: [{
            text: '不知道如何使用',
            isselect: false,
            value: ''
        },
        {
            text: '有重复的企业',
            isselect: false,
            value: ''
        },
        {
            text: '创建错误',
            isselect: false,
            value: ''
        },
        {
            text: '公司业务变动',
            isselect: false,
            value: ''
        },
        {
            text: '使用其他类似的工具',
            isselect: false,
            value: ''
        },
        {
            text: '信息/广告过多',
            isselect: false,
            value: ''
        },
        {
            text: '其他',
            isselect: false,
            value: ''
        }
        ]
    },
    changipt(e) {
        this.setData({
            password: e.detail.value
        })
    },
    submitok() {
        dismisscompanyapi({
            companyId: this.data.id,
            password: this.data.password,
            reason: this.data.resonlist,
            supplement: this.data.areavalue
        }).then((res) => {
            if (this.data.isselect === 'true') {
                user.init()
                app.toast('解散成功，正在为您跳转到首页！')
                setTimeout(() => {
                    wx.reLaunch({
                        url: '/pages/index/index'
                    })
                }, 1000)
            } else {
                wx.reLaunch({
                    url: '/pages/personalmsg/personalmsg',
                })
            }
        })
    },
    close() {
        this.setData({
            isUp: false
        })
    },
    changeeye() {
        console.log(1111)
        this.setData({
            isopeneye: !this.data.isopeneye
        })
    },
    changeipt(e) {
        console.log(e)
        this.setData({
            areavalue: e.detail.value,
            num: e.detail.cursor
        })
    },
    changeselect(e) {
        this.data.selectlist.forEach((ele, i) => {
            if (i === e.currentTarget.dataset.i) {
                ele.isselect = !ele.isselect
            }
        })
        this.setData({
            selectlist: this.data.selectlist
        })
    },
    sure() {
        this.setData({
            password: ''
        })
        let arr = []
        this.data.selectlist.forEach((ele, i) => {
            if (ele.isselect) {
                arr.push(ele.text)
            }
        })
        if (arr.length === 0) {
            wx.showToast({
                title: '请选择解散原因',
                icon: 'error'
            })
        } else {
            this.data.resonlist = arr
            getcheckdismisscompanystatusapi({
                companyId: this.data.id
            }).then((res) => {
                if (!res.hasBalance && !res.hasNotApproval && !res.hasUnclaimed) {
                    if (res.isHavePassword) {
                        this.setData({
                            isUp: true
                        })
                    }else{
                        this.submitok()
                    }
                  
                } else {
                    this.setData({
                        hasreasonmsg: res,
                        isUptwo: true
                    })
                }
            })
        }
    },
    closeisuptwo() {
        this.setData({
            isUptwo: false
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log(options)
        this.data.id = options.companyid
        this.data.isselect = options.isselect
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})